/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/*
 * listaPagosPendientesBanco.java
 *
 * Created on Jan 7, 2012, 9:29:26 AM
 */

package FACTURAS;

import INTERFAZ.*;
import CONTROLES.ControlSucursal;
import MODELOS.Sucursal;
import Reportes.Reporte;
import UTILITARIOS.Herramienta;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import UTILITARIOS.MiModelo;
import UTILITARIOS.StringToDate;
import java.awt.event.ActionListener;
import java.util.Calendar;
import java.util.StringTokenizer;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;

/**
 *
 * @author VICENTE
 */
public class LibroCompras extends javax.swing.JDialog {
    /** Creates new form listaPagosPendientesBanco */
    public LibroCompras(javax.swing.JFrame parent, boolean modal){
        super(parent, modal);
        initComponents();
        iniciarComponentes();
        addEventos();
    }

    private void iniciarComponentes(){

        controlFactura = new ControlFacturaCompra();
        fechaActual = Calendar.getInstance();
        inicio = Calendar.getInstance();
        
        choice3.add("Enero");
        choice3.add("Febrero");
        choice3.add("Marzo");
        choice3.add("Abril");
        choice3.add("Mayo");
        choice3.add("Junio");
        choice3.add("Julio");
        choice3.add("Agosto");
        choice3.add("Septiembre");
        choice3.add("Octubre");
        choice3.add("Noviembre");
        choice3.add("Diciembre");        
        choice3.select(inicio.get(Calendar.MONTH));

        for(int r=0; r<3; r++)
            choice2.add(String.valueOf(inicio.get(Calendar.YEAR)-1+r));
        choice2.select(String.valueOf(inicio.get(Calendar.YEAR)));
        
        sucursal = Bienvenida.sucursal;
        fin = Calendar.getInstance();
        inicio.set(fechaActual.get(Calendar.YEAR),fechaActual.get(Calendar.MONTH),fechaActual.get(Calendar.DATE),0,0,0);
        inicio.add(Calendar.DAY_OF_MONTH, -(inicio.get(Calendar.DAY_OF_MONTH))+1);        

        fin.setTime(inicio.getTime());
        fin.add(Calendar.MONTH,1);
        
        jLabel11.setText(sucursal.getNombreSuc());
        jLabel3.setText(String.valueOf(inicio.get(Calendar.MONTH)+1)+"/"+inicio.get(Calendar.YEAR));
        jLabel4.setText("NFN S.R.L.");
        jLabel5.setText(String.valueOf(sucursal.getNitSucursal()));
        jLabel11.setText("Sucursal - "+String.valueOf(sucursal.getIdSucursal()-1));
        jLabel12.setText(sucursal.getDireccionSuc());
        
        String sucursales[] = new ControlSucursal().nombresSuc();        
        for(int i = 0; i<sucursales.length; i++)
           choice1.add(sucursales[i]);

        choice1.select(sucursal.getIdSucursal()+"-"+sucursal.getNombreSuc());
        
        if(Bienvenida.user.getTipoUsuario().equalsIgnoreCase("ADMINISTRADOR") && Bienvenida.user.getToken().equalsIgnoreCase("INGRESAR") ){
           choice1.setEnabled(true);
           }else{
           choice1.setEnabled(false);
           }

        listaFacturas = controlFactura.getFacturasCompraMes(sucursal.getIdSucursal(), inicio.getTime(), fin.getTime());

        cargarTabla();
    }
    
    private void addEventos(){

        jButton1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {

                StringTokenizer s = new StringTokenizer(choice1.getSelectedItem(),"-");
                int idSucursal = Integer.parseInt(s.nextToken());

                int mes = Integer.valueOf(choice3.getSelectedIndex());
                int anio = Integer.valueOf(choice2.getSelectedItem());
                inicio.set(anio,mes,1,0,0,0);
                fin.setTime(inicio.getTime());
                fin.add(Calendar.MONTH,1);

                jLabel11.setText(sucursal.getNombreSuc());
                jLabel3.setText(String.valueOf(inicio.get(Calendar.MONTH)+1)+"/"+inicio.get(Calendar.YEAR));
                jLabel4.setText("NFN S.R.L.");
                jLabel5.setText(String.valueOf(sucursal.getNitSucursal()));
                jLabel11.setText("Sucursal - "+String.valueOf(sucursal.getIdSucursal()-1));
                jLabel12.setText(sucursal.getDireccionSuc());

                listaFacturas = controlFactura.getFacturasCompraMes(idSucursal, inicio.getTime(), fin.getTime());

                cargarTabla();
            }
        });
        jButton2.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                dispose();
                Reporte r = new Reporte();
                r.ejecutarLibroCompras(sucursal.getIdSucursal(), inicio, fin);
            }
        });
        salir.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                dispose();
            }
        });
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        pagos = new javax.swing.JTable();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        salir = new javax.swing.JButton();
        jLabel11 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        choice1 = new java.awt.Choice();
        jLabel2 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        choice2 = new java.awt.Choice();
        choice3 = new java.awt.Choice();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Libro de Compras IVA");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "", javax.swing.border.TitledBorder.LEFT, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Times New Roman", 0, 14))); // NOI18N
        jPanel1.setName("jPanel1"); // NOI18N

        jPanel2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel2.setName("jPanel2"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        pagos.setName("pagos"); // NOI18N
        jScrollPane1.setViewportView(pagos);

        jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel8.setText("TOTAL IVA CREDITO FISCAL");
        jLabel8.setName("jLabel8"); // NOI18N

        jLabel9.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel9.setText("jLabel9");
        jLabel9.setName("jLabel9"); // NOI18N

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap(929, Short.MAX_VALUE)
                        .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 177, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 1217, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 308, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(jLabel9))
                .addContainerGap(13, Short.MAX_VALUE))
        );

        jLabel1.setFont(new java.awt.Font("Times New Roman", 0, 12));
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("LIBRO DE COMPRAS IVA");
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel3.setFont(new java.awt.Font("Times New Roman", 0, 12)); // NOI18N
        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel3.setText("periodo fiscal");
        jLabel3.setName("jLabel3"); // NOI18N

        salir.setFont(new java.awt.Font("Tahoma", 0, 12));
        salir.setText("SALIR");
        salir.setName("salir"); // NOI18N

        jLabel11.setFont(new java.awt.Font("Times New Roman", 0, 12));
        jLabel11.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel11.setText("SUCURSAL");
        jLabel11.setName("jLabel11"); // NOI18N

        jLabel4.setFont(new java.awt.Font("Times New Roman", 0, 12));
        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel4.setText("Razon social");
        jLabel4.setName("jLabel4"); // NOI18N

        jLabel5.setFont(new java.awt.Font("Times New Roman", 0, 12));
        jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel5.setText("NIT");
        jLabel5.setName("jLabel5"); // NOI18N

        jLabel12.setFont(new java.awt.Font("Times New Roman", 0, 12));
        jLabel12.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel12.setText("DIRECCION");
        jLabel12.setName("jLabel12"); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 1229, Short.MAX_VALUE)
            .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 1229, Short.MAX_VALUE)
            .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, 1229, Short.MAX_VALUE)
            .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 1229, Short.MAX_VALUE)
            .addComponent(jLabel11, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 1229, Short.MAX_VALUE)
            .addComponent(jLabel12, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 1229, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(salir))
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 8, Short.MAX_VALUE)
                .addComponent(jLabel11)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel12)
                .addGap(10, 10, 10)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(salir))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Criterios de busqueda"));
        jPanel3.setName("jPanel3"); // NOI18N

        choice1.setName("choice1"); // NOI18N

        jLabel2.setFont(new java.awt.Font("Times New Roman", 0, 12));
        jLabel2.setText("Elegir Sucursal");
        jLabel2.setName("jLabel2"); // NOI18N

        jButton1.setText("Listar");
        jButton1.setName("jButton1"); // NOI18N

        choice2.setName("choice2"); // NOI18N

        choice3.setName("choice3"); // NOI18N

        jLabel6.setText("Mes:");
        jLabel6.setName("jLabel6"); // NOI18N

        jLabel7.setText("Año:");
        jLabel7.setName("jLabel7"); // NOI18N

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel2)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                        .addComponent(choice3, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel7)
                        .addGap(30, 30, 30)
                        .addComponent(choice2, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(choice1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 285, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton1)
                .addGap(37, 37, 37))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(choice1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 24, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton1)
                    .addComponent(jLabel6)
                    .addComponent(jLabel7)
                    .addComponent(choice3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(choice2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jButton2.setText("Imprimir");
        jButton2.setName("jButton2"); // NOI18N

        jButton3.setText("Editar Factura");
        jButton3.setName("jButton3"); // NOI18N
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(384, Short.MAX_VALUE)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 490, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(137, 137, 137)
                .addComponent(jButton3)
                .addGap(48, 48, 48)
                .addComponent(jButton2)
                .addContainerGap())
            .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jButton2)
                        .addComponent(jButton3))
                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(11, 11, 11)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        if(pagos.getValueAt(pagos.getSelectedRow(), 0)!= null){
                    String x = (pagos.getValueAt(pagos.getSelectedRow(), 3)).toString();
                    System.out.println(x+"=valor x");

                    FacturaCompra f = new ControlFacturaCompra().dameFacturaCompra(x);
                    System.out.println(f.getIdFacturaCompra()+"=idddd");
                    java.text.SimpleDateFormat sdf=new java.text.SimpleDateFormat("dd-MM-yyyy");
                    String fecha = sdf.format(f.getFecha());
                    EditarFacturaCompra fact = new EditarFacturaCompra(new javax.swing.JFrame());

                    
                    fact.settxtNit(f.getNitCliente());
                    fact.settxtCliente(f.getCliente());
                    fact.settxtNumFac(f.getNumFactura());
                    fact.settxtNumAutorizacion(f.getNumAutorizacion());
                    fact.settxtICE(String.valueOf(f.getIce()));
                    fact.settxtExento(String.valueOf(f.getExento()));
                    fact.settxtImporte(String.valueOf(f.getMonto()));
                    fact.settxtFechaCreado(fecha);
                    fact.setChoiseIdSucursal(f.getIdSucursal()+"-"+new ControlSucursal().dameNomSucursal(f.getIdSucursal()));
                    fact.settxtCodigoControl(f.getCodigoControl());

                    Herramienta.centerOnScreen(fact);
                    fact.setModal(true);
                    fact.setVisible(true);
                    
                    
                   

                   
                }

    }//GEN-LAST:event_jButton3ActionPerformed


    /**
    * @param args the command line arguments
    */

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private java.awt.Choice choice1;
    private java.awt.Choice choice2;
    private java.awt.Choice choice3;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable pagos;
    private javax.swing.JButton salir;
    // End of variables declaration//GEN-END:variables
    private MiModelo modelo_pagos;

    ArrayList<FacturaCompra> listaFacturas;
    
    private ControlFacturaCompra controlFactura;
    private Sucursal sucursal;
    private Calendar fechaActual;
    private Calendar inicio;
    private Calendar fin;

    private void cargarTabla(){

        modelo_pagos = new MiModelo(new Object [][] {},new String [] {"Fecha", "NIT", "Razon Social", "Nº factura", "Autorización", "Codigo Control", "Importe","ICE", "Excento", "Importe para Iva","Credito Fiscal"}, -1);
        StringToDate ds = new StringToDate();
        FacturaCompra p;
        double importe;
        double totalIva= 0;
        double iva;
        if(listaFacturas.size()>0){
            for(int i=0;i<listaFacturas.size();i++){
                p = listaFacturas.get(i);
                importe = (Herramienta.redondear(p.getMonto(), 2)+Herramienta.redondear(p.getIce(), 2)+Herramienta.redondear(p.getExento(), 2));
                iva = Herramienta.redondear(importe*0.13, 2);
                Object [] auxPago = {
                    ds.dateAstring(p.getFecha()),
                    p.getNitCliente(),
                    p.getCliente(),
                    p.getNumFactura(),
                    p.getNumAutorizacion(),
                    p.getCodigoControl(),
                    Herramienta.redondearDoubleString(p.getMonto()),
                    Herramienta.redondearDoubleString(p.getIce()),
                    Herramienta.redondearDoubleString(p.getExento()),
                    (int)importe,
                    Herramienta.redondearDoubleString(iva)
                };
                totalIva = totalIva+iva;
                modelo_pagos.addRow(auxPago);
            }
        }
        jLabel9.setText(String.valueOf(Herramienta.redondearDoubleString(totalIva)));
        pagos.setModel(modelo_pagos);
        DefaultTableCellRenderer tcr = new DefaultTableCellRenderer();
        tcr.setHorizontalAlignment(SwingConstants.RIGHT);

        DefaultTableCellRenderer tcrc = new DefaultTableCellRenderer();
        tcrc.setHorizontalAlignment(SwingConstants.CENTER);

        pagos.getColumnModel().getColumn(0).setMaxWidth(70);
        pagos.getColumnModel().getColumn(0).setCellRenderer(tcrc);
        pagos.getColumnModel().getColumn(1).setMaxWidth(110);
        pagos.getColumnModel().getColumn(1).setMinWidth(110);
        pagos.getColumnModel().getColumn(1).setCellRenderer(tcrc);
        pagos.getColumnModel().getColumn(2).setCellRenderer(tcrc);
        pagos.getColumnModel().getColumn(3).setMaxWidth(90);
        pagos.getColumnModel().getColumn(3).setCellRenderer(tcr);
        pagos.getColumnModel().getColumn(4).setMaxWidth(120);
        pagos.getColumnModel().getColumn(4).setMinWidth(120);
        pagos.getColumnModel().getColumn(4).setCellRenderer(tcr);
        pagos.getColumnModel().getColumn(5).setMaxWidth(120);
        pagos.getColumnModel().getColumn(5).setMinWidth(120);
        pagos.getColumnModel().getColumn(5).setCellRenderer(tcrc);
        pagos.getColumnModel().getColumn(6).setMaxWidth(100);
        pagos.getColumnModel().getColumn(6).setMinWidth(100);
        pagos.getColumnModel().getColumn(6).setCellRenderer(tcr);
        pagos.getColumnModel().getColumn(7).setMaxWidth(70);
        pagos.getColumnModel().getColumn(7).setCellRenderer(tcr);
        pagos.getColumnModel().getColumn(8).setMaxWidth(70);
        pagos.getColumnModel().getColumn(8).setCellRenderer(tcr);
        pagos.getColumnModel().getColumn(9).setMaxWidth(95);
        pagos.getColumnModel().getColumn(9).setMinWidth(95);
        pagos.getColumnModel().getColumn(9).setCellRenderer(tcr);
        pagos.getColumnModel().getColumn(10).setMaxWidth(85);
        pagos.getColumnModel().getColumn(10).setMinWidth(85);
        pagos.getColumnModel().getColumn(10).setCellRenderer(tcr);
    }
    public static void main(String args[]) {
        LibroCompras l = new LibroCompras(null, true);
        l.setVisible(true);
    }
}
